from ceph.ceph_manager import global_configs
from ceph.models import CephCluster
from ceph.models import GlobalConfig


def setup_global_config():
    try:
        global_configs.get_configs()
    except Exception as e:
        pass
    return


def setup_ceph_config():
    try:
        ceph_clusters = CephCluster.objects.all()
        if ceph_clusters:
            return
    except Exception as e:
        return

    for ceph_cluster in ceph_clusters:
        try:
            ceph_cluster._save_config_to_file()
        except Exception as e:
            pass
    return


def get_yunkun_config():
    local_endpoint = global_configs.get(GlobalConfig.ConfigName.LOCAL_ENDPOINT.value)
    local_endpoint = GlobalConfig.parse_lines(text=local_endpoint)

    yunkun_auth_endpoint = global_configs.get(GlobalConfig.ConfigName.YUNKUN_AUTH_ENDPOINT.value)
    yunkun_auth_name = global_configs.get(GlobalConfig.ConfigName.YUNKUN_AUTH_NAME.value)
    jwt_public_key = global_configs.get(GlobalConfig.ConfigName.AAI_JWT_VERIFYING_KEY.value)

    return local_endpoint, yunkun_auth_endpoint, yunkun_auth_name, jwt_public_key
